package com.sservice.service.service.impl;

import com.sservice.commonBusiness.service.CategoryService;
import com.sservice.commonBusiness.vo.CategoryVo;
import com.sservice.commonBusiness.vo.CommentVo;
import com.sservice.model.dao.IInfoDao;
import com.sservice.model.entity.Info;
import com.sservice.model.vo.InfoVo;
import com.sservice.service.service.IInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class InfoServiceImpl implements IInfoService {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IInfoDao dataDao;
    @Autowired
    CategoryService categoryService;

    /**
     * 根据 COMID 获取片区ID
     *
     * @param comId 回复内容
     * @return
     */
    public String getPianQu(String comId) {
        CategoryVo category = new CategoryVo();
        category.setType1("community");// 获取片区管理
        List<CategoryVo> list = categoryService.queryByPage(category);
        CategoryVo category1 = null;
        for (CategoryVo categoryVo : list
                ) {
            String ids = "," + categoryVo.getRemark() + ",";
            if (ids.indexOf("," + comId + ",") > -1) {
                category1 = categoryVo;
            }
        }
        return category1.getRemark();
    }

    /**
     * 敏感词
     *
     * @param content 回复内容
     * @return
     */
    @Override
    public List<String> filterSensitiveWord(String content) {
        CategoryVo categoryVo = new CategoryVo();
        categoryVo.setType1("sensitive");
        List<CategoryVo> sensitives = categoryService.page(categoryVo);
        List<String> sensitivesList = new ArrayList();////
        sensitives.forEach(item -> {
            if (content!=null&&content.contains(item.getName())) {
                sensitivesList.add(item.getName());
            }
        });
        return sensitivesList;
    }

    @Override
    public List<String> filterEarlyWarning(String content) {
        CategoryVo categoryVo = new CategoryVo();
        categoryVo.setType1("earlyWarning");
        List<CategoryVo> sensitives = categoryService.page(categoryVo);
        List<String> sensitivesList = new ArrayList();
        sensitives.forEach(item -> {
            if (content.contains(item.getName())) {
                sensitivesList.add(item.getName());
            }
        });
        return sensitivesList;
    }

    public List<Info> queryByPage(InfoVo user) {
        return dataDao.queryByPage(user);
    }

    @Override
    public List<InfoVo> queryPlainByPage(InfoVo record) {
        return dataDao.queryPlainByPage(record);
    }

    @Override
    public List<InfoVo> queryfdPlainByPage(InfoVo record) {
        return dataDao.queryfdPlainByPage(record);
    }

    @Override
    public int querydrCount(InfoVo record) {
        return dataDao.querydrCount(record);
    }

    @Override
    public int countPlainByPage(InfoVo record) {
        return dataDao.countPlainByPage(record);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return dataDao.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Info record) {
        return dataDao.insert(record);
    }

    @Override
    public int insertSelective(Info record) {
        return dataDao.insertSelective(record);
    }

    @Override
    public Info selectByPrimaryKey(Integer id) {
        return dataDao.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Info record) {
        return dataDao.updateByPrimaryKeySelective(record);
    }


    @Override
    public int queryCount(InfoVo user) {
        return dataDao.queryCount(user);
    }

    @Override
    public List<InfoVo> queryWithCategoryByPage(InfoVo record) {
        return dataDao.queryWithCategoryByPage(record);
    }

    @Override
    public int countWithCategoryByPage(InfoVo record) {
        return dataDao.countWithCategoryByPage(record);
    }

    @Override
    public List<CommentVo> queryUserRecordByPage(InfoVo record) {
        return dataDao.queryUserRecordByPage(record);
    }

    @Override
    public int countUserRecordByPage(InfoVo record) {
        return dataDao.countUserRecordByPage(record);
    }

    @Override
    public List<InfoVo> queryTplByPage(InfoVo record) {
        return dataDao.queryTplByPage(record);
    }

    @Override
    public int countTplByPage(InfoVo record) {
        return dataDao.countTplByPage(record);
    }
}
